home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / New System Software Extensions / ASLM SDK v1.1.2 / ASLM Examples / Inspector / Sources / Document.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-21  |  5.0 KB  |  166 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TDocument.h
  3.  
  4.     Contains:    TDocument interface
  5.  
  6.     Copyright:    © 1991-1993 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10.  
  11. #ifndef __DOCUMENT__
  12. #define __DOCUMENT__
  13.  
  14. #ifndef __LIBRARYMANAGERCLASSES__
  15. #include <LibraryManagerClasses.h>
  16. #endif
  17.  
  18.  
  19. /*******************************************************************************
  20. ** Forward declarations
  21. ********************************************************************************/
  22.  
  23. class TDocument;
  24. class TDocumentLink;
  25. class TDocumentList;
  26. struct EventRecord;
  27. struct GrafPort;
  28.  
  29.  
  30. // Define HiWrd and LoWrd macros for efficiency
  31. #define HiWrd(aLong)    ((short) (((aLong) >> 16) & 0xFFFF))
  32. #define LoWrd(aLong)    ((short) ((aLong) & 0xFFFF))
  33.  
  34. // Define TopLeft and BotRight macros for convenience. Notice the implicit
  35. // dependency on the ordering of fields within a Rect
  36. #define TopLeft(aRect)    (* (Point *) &(aRect).top)
  37. #define BotRight(aRect)    (* (Point *) &(aRect).bottom)
  38.  
  39. const long kMaxSleepTime = 60;    // 1 second worth of ticks
  40.  
  41. /**********************************************************************
  42. ** class TDocument
  43. ***********************************************************************/
  44.  
  45. #define kTDocumentID "appl:insp$TDocument,1.1"
  46.  
  47. class TDocument : public TDynamic
  48. {
  49. protected:
  50.     GrafPort*         fDocWindow;
  51.     TDocumentList    *fDocList;
  52. public:
  53.     TDocument();
  54.     TDocument(short resID);        // our constructor - creates window using resID as template
  55.     virtual ~TDocument();        // our destructor - disposes of window
  56.  
  57.     // you will need to override these in your subclasses,
  58.     // since they are do-nothing routines by default...
  59.     virtual void DoZoom(short partCode);
  60.     virtual void DoGrow(EventRecord* theEvent);
  61.     virtual void DoContent(EventRecord* theEvent);
  62.     virtual void DoKeyDown(EventRecord* theEvent);
  63.     virtual void DoActivate(Boolean becomingActive);
  64.     virtual void DoUpdate();
  65.     // file handling routines
  66.     virtual void DoOpen();
  67.     virtual void DoClose();
  68.     virtual void DoSave();
  69.     virtual void DoSaveAs();
  70.     virtual void DoRevert();
  71.     virtual void DoPrint();
  72.     // do standard edit menu actions
  73.     virtual void DoUndo();
  74.     virtual void DoCut();
  75.     virtual void DoCopy();
  76.     virtual void DoPaste();
  77.     virtual void DoClear();
  78.     virtual void DoSelectAll();
  79.  
  80.     // idle time routines: you can use these to do cursor handling,
  81.     // TE caret blinking, marquee effects, etc...
  82.     virtual void DoIdle();
  83.     virtual unsigned long CalcIdle();
  84.     virtual void AdjustCursor(Point where);            // where is in local coords
  85.  
  86.     // query state of document - useful for adjusting menu state
  87.     virtual Boolean HaveUndo();
  88.     virtual Boolean HaveSelection();
  89.     virtual Boolean HavePaste();
  90.     virtual Boolean CanClose();
  91.     virtual Boolean CanSave();
  92.     virtual Boolean CanSaveAs();
  93.     virtual Boolean CanRevert();
  94.     virtual Boolean CanPrint();
  95.  
  96.     inline GrafPort* GetDocWindow() { return fDocWindow;} ;
  97.     inline TDocumentList * GetDocList() { return fDocList; };
  98.     inline void SetDocList(TDocumentList *theDocList) { fDocList = theDocList; };
  99.     
  100. private:
  101.     virtual    void        InitDocument(short resID);
  102. };
  103.  
  104.  
  105. /**********************************************************************
  106. ** class TDocumentList
  107. ***********************************************************************/
  108.  
  109. #define kTDocumentListID "appl:insp$TDocumentList,1.1"
  110.  
  111. // TDocumentList is a simple linked list of documents, implemented C++
  112. // style. I could have made a general linked list class & just made
  113. // this a subclass. This would have been a more general (and more
  114. // object-oriented) solution, but I did it from scratch in a futile
  115. // attempt at keeping the size of this program at a reasonable level.
  116.  
  117. class TDocumentList : public TDynamic 
  118. {
  119.     TDocumentLink*    fDocList;    // the first link in our list
  120.     int                fNumDocs;    // the number of elements in the list
  121.  
  122. public:
  123.                             TDocumentList();    // our constructor
  124.     virtual                    ~TDocumentList();    // our destructor
  125.  
  126.     virtual void            AddDoc(TDocument* doc);
  127.     virtual void            RemoveDoc(TDocument* doc);
  128.     virtual TDocument*        FindDoc(GrafPort* window);
  129.     inline int                NumDocs() { return fNumDocs; }
  130.     inline TDocumentLink*    FirstDoc() { return fDocList; }
  131. };
  132.  
  133.  
  134. /**********************************************************************
  135. ** class TDocumentLink
  136. ***********************************************************************/
  137.  
  138. // TDocumentLink is a simple utility class which is used by
  139. // the TDocumentList class below. You cannot allocate
  140. // objects of this type yourself, since its constructor
  141. // is private. We get around this for TDocumentList by
  142. // making it a "friend" of this class. This is a handy
  143. // trick.
  144. class TDocumentLink : public TLink
  145. {
  146.     friend class TDocumentList;
  147.  
  148.     // our constructor. Note that it can take args for convenience,
  149.     // but that they default to NULL.
  150.                             TDocumentLink(TDocumentLink *n = NULL, TDocument *v = NULL);
  151.                             ~TDocumentLink() {};
  152.  
  153.             void             SetDoc(TDocument* aDoc) { SetValue(aDoc); };
  154.  
  155. public:
  156.             TDocumentLink*    GetNext() { return (TDocumentLink*)TLink::GetNext(); };
  157.             TDocument*         GetDoc() { return (TDocument*)GetValue(); };
  158. };
  159.  
  160.  
  161. inline TDocumentLink::TDocumentLink(TDocumentLink* n, TDocument* v) :
  162.     TLink(n, v)
  163. {}
  164.  
  165. #endif
  166.